package com.java.netty.server.vnc;

import com.alibaba.fastjson.JSON;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ServerHandler extends ChannelInboundHandlerAdapter {

   public ServerHandler() {
   }

   @Override
   public void channelActive(ChannelHandlerContext ctx) throws Exception {
      Channel channel = ctx.channel();
      System.out.println(channel.remoteAddress() + "上线");
   }

   @Override
   public void channelInactive(ChannelHandlerContext ctx) throws Exception {
      Channel channel = ctx.channel();
      System.out.println(channel.remoteAddress() + "下线");
   }

   @Override
   public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
      //解析java-netty-client 发过来的包
      System.out.println(msg);

   }

   @Override
   public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
      System.out.println("channelReadComplete");
   }

   @Override
   public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
      cause.printStackTrace();
      ctx.close();
   }

   @Override
   public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
      super.handlerAdded(ctx);
   }

   @Override
   public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
      super.handlerRemoved(ctx);
   }
}
